$(function(){
    var auditInsurance_datagrid,auditInsurance_form;
    auditInsurance_datagrid = $("#auditInsurance_datagrid");
    auditInsurance_form = $("#auditInsurance_form");
    auditInsurance_datagrid.datagrid({
        fit:true,
        fitColumns:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        toolbar:$("#auditInsurance_datagrid_tb"),
        url:'/auditInsurance/list',
        columns:[[
            {field:'organization',title:'承保机构',width:10,align:'center',formatter:organizationFormatter},
            {field:'bill',title:'申请单号',width:10,align:'center',formatter:billFormatter},
            {field:'product',title:'产品名称',width:10,align:'center',formatter:productFormatter},
            {field:'client',title:'投保人',width:10,align:'center',formatter:clientFormatter},
            {field:'insuranceInfoChange',title:'申请时间',width:10,align:'center',formatter:insuranceInfoChangeFormatter},
            {field:'dept',title:'任务提交部门',width:10,align:'center',formatter:deptFormatter},
            {field:'emp',title:'任务提交人',width:10,align:'center',formatter:empFormatter},
            {field:'pushTime',title:'提交时间',width:10,align:'center'}
        ]]
    });

    var cmdObj={
        //保存
        save:function(){
            var rowData = auditInsurance_datagrid.datagrid("getSelected");
            if (rowData) {
                $.messager.confirm("温馨提示", "确定要提交吗?", function (yes) {
                    if (yes) {
                        $.get("/auditInsurance/update?id=" + rowData.id, function (data) {
                            if (data.success) {
                                roleDatagrid.datagrid("reload");
                                $.messager.alert("温馨提示", data.msg, "info");
                            }
                        }, "json")
                    } else {
                        $.messager.alert("温馨提示", data.msg, "error");
                    }
                })
            } else {
                $.messager.alert("瞧我这暴脾气", "你丫要我弄谁呢?能不闹吗?", "warning");
            }
        },











        search:function () {
            var organizationId  = $("[name=organizationId]").val();
            var cliendName  = $("[name=cliendName]").val();
            var productId  = $("[name=productId]").val();
            var billNumber  = $("[name=billNumber]").val();
            var minDate  = $("[name=minDate]").val();
            var maxDate  = $("[name=maxDate]").val();

            if (minDate == ""){
                minDate = '01/01/1949'
            }
            if (maxDate == ""){
                maxDate = '01/01/2088'
            }
            auditInsurance_datagrid.datagrid("load",{
                organizationId:organizationId,
                cliendName:cliendName,
                productId:productId,
                billNumber:billNumber,
                minDate:minDate,
                maxDate:maxDate
            })
        },
        reload:function () {
            auditInsurance_form.form("clear");
            var organizationId  = $("[name=organizationId]").val();
            var cliendName  = $("[name=cliendName]").val();
            var productId  = $("[name=productId]").val();
            var billNumber  = $("[name=billNumber]").val();
            var minDate  = $("[name=minDate]").val();
            var maxDate  = $("[name=maxDate]").val();

            if (minDate == ""){
                minDate = '01/01/1949'
            }
            if (maxDate == ""){
                maxDate = '01/01/2088'
            }
            auditInsurance_datagrid.datagrid("load",{
                organizationId:organizationId,
                cliendName:cliendName,
                productId:productId,
                billNumber:billNumber,
                minDate:minDate,
                maxDate:maxDate
            })
        }
    };


    $("a[data-cmd]").on("click",function(){
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })




});

function organizationFormatter(value,row,index){
    return value? value.organizationName:"";
}

function billFormatter(value,row,index){
    return value? value.orderBillNumber:"";
}

function productFormatter(value,row,index){
    return value? value.name:"";
}

function clientFormatter(value,row,index){
    return value? value.realName:"";
}

function insuranceInfoChangeFormatter(value,row,index){
    return value? value.auditinsurancetime:"";
}

function deptFormatter(value,row,index){
    return value? value.name:"";
}

function empFormatter(value,row,index){
    return value? value.name:"";
}








